//
//  BNDOfficeDocReadView.m
//  OfficeDoc
//
//  Created by pie on 2022/4/3.
//  Copyright © 2022 pie. All rights reserved.
//

#import "BNDOfficeDocReadView.h"
#import "BNDOfficeDocReadVc.h"
#import "BNDPushVCHandler.h"
#import "UIImage+YYAdd.h"
#import "BNDOfficeDocKit.h"

@interface BNDOfficeDocReadView ()
@property (strong, nonatomic) UILabel *readLabel;
@property (strong, nonatomic) UILabel *signLabel;
@property (copy,   nonatomic) NSString *readCount;
@property (copy,   nonatomic) NSString *readHasBeenSigned;
@property (copy,   nonatomic) NSString *readUnsigned;
@property (copy,   nonatomic) NSString *unreadCount;
@end

@implementation BNDOfficeDocReadView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        UIImageView *readImageView = [[UIImageView alloc] initWithImage:BNDImageNamed(@"bnd_icon_baifenbi")];
        [self addSubview:readImageView];
        [readImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.mas_left).offset(16);
            make.centerY.mas_equalTo(self);
            make.size.mas_equalTo(CGSizeMake(14, 14));
        }];
 
    
        _readLabel = [[UILabel alloc] init];
        _readLabel.font = BNDPFRegularFont(12);
        _readLabel.textColor = UIColorWithHex(0x7F848B);
        _readLabel.text = @"已读33/未读13";
        _readLabel.textAlignment = NSTextAlignmentCenter;
        _readLabel.numberOfLines = 1;
        [self addSubview:_readLabel];
        [_readLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(readImageView.mas_right).offset(2);
            make.centerY.mas_equalTo(readImageView);
        }];

    
        _signLabel = [[UILabel alloc] init];
        _signLabel.font = BNDPFRegularFont(12);
        _signLabel.textColor = UIColorWithHex(0x7F848B);
        _signLabel.text = @"已签10/未签36";
        _signLabel.textAlignment = NSTextAlignmentRight;
        _signLabel.numberOfLines = 1;
        [self addSubview:_signLabel];
        [_signLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.mas_right).offset(-16);
            make.centerY.mas_equalTo(readImageView);
        }];
        
        
        UIImageView *signImageView = [[UIImageView alloc] initWithImage:BNDImageNamed(@"bnd_icon_qianshu")];
        [self addSubview:signImageView];
        [signImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.signLabel.mas_left).offset(-3);
            make.centerY.mas_equalTo(self);
            make.size.mas_equalTo(CGSizeMake(14, 14));
        }];
        
        @weakify(self)
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
        [[tap rac_gestureSignal] subscribeNext:^(id x) {
            @strongify(self)
            BND_dispatch_main_sync_safe(^{
                BNDOfficeDocReadVc *vc = [[BNDOfficeDocReadVc alloc] init:self.readCount readHasBeenSigned:self.readHasBeenSigned readUnsigned:self.readUnsigned unreadCount:self.unreadCount];
                vc.title = @"阅读详情";
                vc.announcementId = self.model.modelID;
                [[BNDPushVCHandler currentSelectedNavController] pushViewController:vc animated:YES];
            });
        }];
        [self addGestureRecognizer:tap];
        
    }
    
    return self;
}

- (void)handleData:(NSString *)readCount readHasBeenSigned:(NSString *)readHasBeenSigned readUnsigned:(NSString *)readUnsigned unreadCount:(NSString *)unreadCount
{
    self.readCount = readCount;
    self.readHasBeenSigned = readHasBeenSigned;
    self.readUnsigned = readUnsigned;
    self.unreadCount = unreadCount;
    
    _readLabel.text = [NSString stringWithFormat:@"已读%@/未读%@",TTStringNilToZero(readCount),TTStringNilToZero(unreadCount)];
    _signLabel.text = [NSString stringWithFormat:@"已签%@/未签%@",TTStringNilToZero(readHasBeenSigned),TTStringNilToZero(readUnsigned)];

}

@end
